#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDir>
#include <QFileInfo>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    //通过文件对话框获取目录
    QString dirpath = QFileDialog::getExistingDirectory(this);

    //创建目录对象
    QDir dir(dirpath);

    //遍历目录
    QFileInfoList list = dir.entryInfoList();
    for(int i = 0;i<list.count();i++){
        QFileInfo info = list.at(i);
        if(info.isDir()){
            QIcon icon(":/dir.png");
            QListWidgetItem *item = new QListWidgetItem(icon,info.fileName());
            ui->listWidget->addItem(item);

        }else if(info.isFile()){
            QIcon icon(":/file.png");
            QListWidgetItem *item = new QListWidgetItem(icon,info.fileName());
            ui->listWidget->addItem(item);
        }
    }
}
